using System;
using Godot;

public partial class WeaponManager : Node
{
    [Signal]
    public delegate void OnWeaponUseEventHandler(WeaponEntity weapon);

    [Signal]
    public delegate void OnWeaponUseEndEventHandler(WeaponEntity weapon);

    static WeaponManager Instance;

    public override void _Ready()
    {
        Instance = this;
    }

    public static WeaponEntity Create(SkillModel md, Robot robot)
    {
        WeaponEntity weapon = null;
        if (md.CastType == SkillCastType.NoTarget)
        {
            weapon = new WeaponEnemyNoTarget(md, robot);
        }
        else if (md.CastType == SkillCastType.Target && (md.StringID == "RangeWeapon" || md.StringID == "MeleeWeapon"))
        {
            weapon = new WeaponEnemyTarget(md, robot);
        }
        else if (md.CastType == SkillCastType.Target && md.StringID == "HealSkill")
        {
            weapon = new WeaponHeal(md, robot);
        }
        weapon.OnCastStart += OnCastStartHandler;
        weapon.OnCastEnd += OnCastEndHandler;
        return weapon;
    }

    private static void OnCastEndHandler(SkillEventEntity e)
    {
        GameManager.Instance.AllowInput();
        Instance.EmitSignal(SignalName.OnWeaponUseEnd, e.Skill);
    }

    private static void OnCastStartHandler(SkillEventEntity e)
    {
        GameManager.Instance.LockInput();
        Instance.EmitSignal(SignalName.OnWeaponUse, e.Skill);
    }
}